home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / KMAGV2.ZIP / KEYEXAM.PAS < prev    next >
Pascal/Delphi Source File  |  1995-10-22  |  3KB  |  111 lines

  1. {KEYEXAM.PAS / EXAMPLE FOR KEYBOARD INTERRUPT ROUTINES}
  2. {WRITING BY THE KING IN 10/19/95                      }
  3. Uses Dos,Crt;
  4. Const
  5.     RIGHTARROW =  75;        {Right Coursr Key}
  6.     LEFTARROW  =  77;         {Left Coursr Key}
  7.     UPARROW    =  72;        {Up Coursr Key}
  8.     DOWNARROW  =  80;        {Down Coursr Key}
  9.  
  10.     {Ranges !}
  11.     MINRANGEX = 1;
  12.     MINRANGEY = 2;
  13.     MAXRANGEX = 79;
  14.     MAXRANGEY = 24;
  15. Var
  16.     OldInt9 : PRocedure; {The Old Interrupt 9}
  17.     Keys : Array[1..128] Of Boolean;  {The Keys status}
  18.  
  19. {--------------------------------------------}
  20. {New Interrupt 9 for handle with the keyboard}
  21. {--------------------------------------------}
  22.  
  23. Procedure NewInt9;interrupt;
  24. Begin
  25.     Keys[Port[$60] Mod 128] := (Port[$60] < 128) ;
  26.     {Checking if Port[$60] < 128 , If He Is , Keys[Port[$60] Mod 128]
  27.     Is True Else False}
  28.     Asm
  29.         PushF                       {Pushing Flags}
  30.     End;
  31.     OldInt9;                        {Calling the old interrupt}
  32.     Mem[$0040:$001A] := Mem[$0040:$001C];
  33.     {Puting The Tail And The Head , for clear the buffer}
  34. End;
  35. {-------------------------------------------}
  36. {         Init The new interrupt            }
  37. {-------------------------------------------}
  38.  
  39. Procedure Init;
  40. Begin
  41.     GetIntVec($9,@OldInt9);
  42.     SetIntVec($9,@NewInt9);
  43. End;
  44.  
  45. {--------------------------------------}
  46. {      Restore The Old interrupt       }
  47. {--------------------------------------}
  48. Procedure Restore;
  49. Begin
  50.     SetIntVec($9,@OldInt9);
  51. End;
  52.  
  53. {-------------------------------------------}
  54. {      Moving A Man On The Screen           }
  55. {-------------------------------------------}
  56.  
  57. Procedure MoveMan;
  58. Var
  59.     X,Y:Byte;          {The X,Y Of the man}
  60. Begin
  61.     Clrscr;                  {clearing the screen}
  62.     TextColor(15);           {textcolor = White}
  63.     TextBackGround(1);       {textbackground = Blue}
  64.     GotoXy(1,1);
  65.     Writeln(' THE KING KEYBOARD INTERRUPT ROUTINES , PRESS "ESC" TO EXIT , USE THE COURSRS   ');
  66.     TextBackGround(0);       {textbackground = black}
  67.     X:=40;
  68.     Y:=17;
  69.     Repeat
  70.         GotoXy(X,Y);                {Paint the man}
  71.         Write(Chr(1));
  72.  
  73.         {Keyboard Checking}
  74.         If Keys[LEFTARROW] Then
  75.             Inc(X);
  76.  
  77.         If Keys[RIGHTARROW] Then
  78.             Dec(X);
  79.  
  80.         If Keys[UPARROW] Then
  81.             Dec(Y);
  82.  
  83.         If Keys[DOWNARROW] Then
  84.             Inc(Y);
  85.  
  86.         {Checking if the man cross the ranges}
  87.         If X < MINRANGEX Then
  88.             Inc(X);
  89.  
  90.         If Y < MINRANGEY Then
  91.             Inc(Y);
  92.  
  93.         If X > MAXRANGEX Then
  94.             Dec(X);
  95.  
  96.         If Y > MAXRANGEY Then
  97.             Dec(Y);
  98.  
  99.         Delay(50);
  100.         GotoXy(WhereX-1,WhereY);
  101.         Write(' ');
  102.  
  103.     Until(Keys[1]);         {Until ESC Key}
  104.     clrscr;
  105. End;
  106. Begin
  107.     Init;              {INIT KEYBOARD}
  108.     MoveMan;           {MOVING THE MAN}
  109.     Restore;           {RESTORE OLD KEYBOARD}
  110. End.
  111.